package day_2022_12_to_3.year2023;

import java.util.Arrays;

/**
 * @author haomin
 * @date 2023/02/11 22:43
 **/
public class Day2_11_Num2335 {
    class Solution {
        public int fillCups(int[] amount) {
            int max = Math.max(amount[0], Math.max(amount[1], amount[2]));
            int total = amount[0] + amount[1] + amount[2];
            return total <= 2 * max ? max : (total + 1) / 2;
        }
    }

    // 错解
    class Solution2 {
        public int fillCups(int[] amount) {
            int res = 0;
            while(!(amount[0] == 0 && amount[1] == 0 && amount[2] == 0)) {
                Arrays.sort(amount);
                System.out.println(amount[0] + " "+ amount[1] +" "+amount[2]);
                if(amount[0] != 0) {
                    res += amount[0];
                    amount[1] -= amount[0];
                    amount[0] = 0;
                }else if(amount[1] != 0) {
                    res += amount[1];
                    amount[2] -= amount[1];
                    amount[1] = 0;
                }else if(amount[2] != 0) {
                    res += amount[2];
                    amount[2] = 0;
                }
            }
            return res;
        }
    }

}